/*
 * @lc app=leetcode.cn id=234 lang=java
 *
 * [234] 回文链表
 */

// @lc code=start

import java.util.List;

import javax.management.ListenerNotFoundException;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public boolean isPalindrome(ListNode head) {
        if(head == null || head.next == null){
            return true;
        }
        List<Integer> array = new ArrayList<>();
        ListNode temp = head;
        while(temp != null){
            array.add(temp.val);
            temp = temp.next;
        }

        // 使用双指针进行比较
        int left = 0, right = array.size() - 1;
        while(left < right){
            if(array.get(left) != array.get(right)){
                return false;
            }
            left++;
            right--;
        }
        return true;
            
    }
}
// @lc code=end

